package org.xmlbinder;

import org.xmlpull.v1.XmlSerializer;

import java.util.Stack;
import java.io.IOException;

/**
 * @author Noble Paul (noble.paul@gmail.com)
 *         Date: Sep 2, 2007
 *         Time: 5:11:54 PM
 */
class TagStack extends Stack<TagStack> {
    String name;

    public TagStack(String n) {
        name = n;
    }

    public void openTag(XmlSerializer ser) throws IOException {
        ser.startTag(null, name);
    }

    public void push(TagStack t, XmlSerializer ser) throws IOException {
        t.openTag(ser);
        super.push(t);
    }

    public void closeTag(XmlSerializer ser) throws IOException {
        ser.endTag(null, name);
    }

    public void attr(String name, String val, XmlSerializer ser) throws IOException {
        ser.attribute(null, name, val);
    }

    public void cdata(String data, XmlSerializer ser) throws IOException {
        ser.text(data);
    }

    public void pop(XmlSerializer ser) throws IOException {
        super.pop().closeTag(ser);
    }

    public String toString() {
        return name;
    }
}